package com.bawei.module_home.http

import com.bawei.module_home.model.AddMerchantBody
import com.bawei.module_home.model.DeviceModel
import com.bawei.module_home.model.NewsBody
import com.bawei.module_home.model.RepairModel
import com.bawei.module_home.model.SignParam
import com.bawei.module_home.model.VisitorBody
import com.bawei.module_home.model.addAreaBody
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import okhttp3.RequestBody
import javax.inject.Inject

class HomeServiceRepository @Inject constructor() {
    @Inject
    @HomeNetModule.CommonHomeApi
    lateinit var api:Api


    //  获取公告信息
    fun getNotice(page:Int,size:Int)= flow {
        emit(api.getServiceList(page,size))
    }.flowOn(Dispatchers.IO)

    //  获取公告信息
    fun getArea(areaId:Int)=flow{
        emit(api.getAreaList(areaId))
    }.flowOn(Dispatchers.IO)



    //  获取会员信息
    fun getVip(userId:Int)= flow {
        emit(api.getVip(userId))
    }.flowOn(Dispatchers.IO)


    //获取设备列表
    fun getDeviceList()=flow{
        emit(api.getDeviceList())
    }.flowOn(Dispatchers.IO)


    //  会员升级
    fun put_upgrade(userId:Int,newMembershipLevel:String)=flow{
        emit(api.put_upgrade(userId,newMembershipLevel))
    }.flowOn(Dispatchers.IO)

    //  添加区域
    fun addArea(body: addAreaBody)=flow{
        emit(api.addArea(body))
    }.flowOn(Dispatchers.IO)

    fun deleteArea(id: Int)=flow {
        emit(api.deleteArea(id))
    }.flowOn(Dispatchers.IO)

        // 区域详情
    fun areaDetail(id: Int)=flow {
        emit(api.areaDetail(id))
    }.flowOn(Dispatchers.IO)

    //来访登记
    fun addVisitor(body: VisitorBody)= flow{
        emit(api.addVisitor(body))
    }.flowOn(Dispatchers.IO)
    //获取来访列表
    fun getVisitor()= flow{
        emit(api.getVisitor())
    }.flowOn(Dispatchers.IO)
    //获取公司
    fun getProfiles()=flow{
        emit(api.getProfiles())
    }.flowOn(Dispatchers.IO)

    fun getProfilesDetail(id: Int)=flow {
        emit(api.getProfilesDetail(id))
    }.flowOn(Dispatchers.IO)

//    //获取入驻
    fun merchant()=flow {
        emit(api.getMerchant())
    }.flowOn(Dispatchers.IO)
//
    fun addMerchant(body: AddMerchantBody)=flow{
        emit(api.addMerchant(body))
    }.flowOn(Dispatchers.IO)

    fun merchantDetail(id: Int)=flow {
        emit(api.getMerchantDetail(id))
    }.flowOn(Dispatchers.IO)
    //  获取所有房屋信息
    fun getAllHouse()=flow{
        emit(api.getAllHouse())
    }.flowOn(Dispatchers.IO)

    fun approveMerchant(id: Int)=flow{
        emit(api.approveMerchant(id))
    }.flowOn(Dispatchers.IO)




    //新增设备
    fun insertDevice(body: DeviceModel)=flow{
        emit(api.insertDevice(body))
    }.flowOn(Dispatchers.IO)
    //设备详情
    fun getDeviceDetail(id:Int)= flow {
        emit(api.getDeviceDetail(id))
    }.flowOn(Dispatchers.IO)

    //物业报修
    fun postRepair(body: RepairModel)=flow{
        emit(api.postRepair(body))
    }.flowOn(Dispatchers.IO)
    //改变设备状态
    fun postDeviceStatus(id: Int,status: String)=flow{
        emit(api.postDeviceStatus(id,status))
    }.flowOn(Dispatchers.IO)
    //删除设备
    fun deleteDevice(id: Int)=flow{
        emit(api.deleteDevice(id))
    }.flowOn(Dispatchers.IO)
    fun getHouse2(regionId:Int)=flow{
        emit(api.getHouse2(regionId))
    }.flowOn(Dispatchers.IO)






    //考勤打卡列表
    fun getSignList(userId: Int)=flow{
        emit(api.getSignList(userId))
    }.flowOn(Dispatchers.IO)

    fun getNews()=flow {
        emit(api.getNews())
    }.flowOn(Dispatchers.IO)

    fun sendNews(body: NewsBody)=flow {
        emit(api.sendNews(body))
    }.flowOn(Dispatchers.IO)


}